package com.bookcloud.java21.chapter10.枚举预定义方法103;

/** 预定义方法 */
public enum ColorEnum {
  RED(101, "红色"),
  GREEN(102, "绿色"),
  BLUE(103, "蓝色");
  private int code;
  private String describe;

  ColorEnum(int code, String describe) {
    this.code = code;
    this.describe = describe;
  }

  public int getCode() {
    return code;
  }

  public String getDescribe() {
    return describe;
  }

  public static ColorEnum getColorEnumValue(String name) {
    for (ColorEnum colorEnum : ColorEnum.values()) {
      if (colorEnum.name().equals(name)) {
        return colorEnum;
      }
    }
    return null;
  }

  @Override
  public String toString() {
    return "ColorEnum{" + "code=" + code + ", describe='" + describe + '\'' + '}';
  }

  public static void main(String[] args) {
    // 打印出红色
    System.out.println(ColorEnum.RED);
    System.out.println("编码:" + ColorEnum.RED.code);
    System.out.println("描述:" + ColorEnum.RED.describe);
    for (ColorEnum colorEnum : ColorEnum.values()) {
      System.out.println(colorEnum.code + "," + colorEnum.describe + "," + colorEnum.name());
    }
  }
}
